package cn.lumin.mock.domain;

import com.cutefool.dsl.mybatis.core.objects.BasicsDomain;
import com.fasterxml.jackson.annotation.JsonAlias;
import jakarta.annotation.Generated;
import java.math.BigDecimal;
import java.sql.JDBCType;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.UnaryOperator;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.insert.InsertDSL;
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateModel;

@Data
@EqualsAndHashCode(callSuper = true)
public class ExecutionInfo extends BasicsDomain<Long, ExecutionInfo> {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TRADING_UNIT")
    private String tradingUnit;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TRADING_UNIT_ID")
    private String tradingUnitId;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("MARKET_ID")
    private String marketId;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TARGET_DATE")
    private LocalDate targetDate;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TIME_CODE")
    private Byte timeCode;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TRADING_DIRECTION")
    private String tradingDirection;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("DEAL_PRICE")
    private BigDecimal dealPrice;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("DEAL_ENERGY")
    private BigDecimal dealEnergy;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("BID_TIME")
    private LocalDateTime bidTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("DEAL_TIME")
    private LocalDateTime dealTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("BID_PRICE")
    private BigDecimal bidPrice;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("BID_ENERGY")
    private BigDecimal bidEnergy;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("VEN_LISTING_ID")
    private String venListingId;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("SALE_LISTING_ID")
    private String saleListingId;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TENANT_ID")
    private String tenantId;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("CREATE_DEPT")
    private Long createDept;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("CREATE_TIME")
    private LocalDateTime createTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("UPDATE_TIME")
    private LocalDateTime updateTime;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("ORG_CODE")
    private String orgCode;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("TRADING_DATE")
    private LocalDate tradingDate;

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @JsonAlias("GUID")
    private String guid;

    private static final Table table = new Table();

    public static final String FIELD_ID = "id";

    public static final String FIELD_TRADING_UNIT = "tradingUnit";

    public static final String FIELD_TRADING_UNIT_ID = "tradingUnitId";

    public static final String FIELD_MARKET_ID = "marketId";

    public static final String FIELD_TARGET_DATE = "targetDate";

    public static final String FIELD_TIME_CODE = "timeCode";

    public static final String FIELD_TRADING_DIRECTION = "tradingDirection";

    public static final String FIELD_DEAL_PRICE = "dealPrice";

    public static final String FIELD_DEAL_ENERGY = "dealEnergy";

    public static final String FIELD_BID_TIME = "bidTime";

    public static final String FIELD_DEAL_TIME = "dealTime";

    public static final String FIELD_BID_PRICE = "bidPrice";

    public static final String FIELD_BID_ENERGY = "bidEnergy";

    public static final String FIELD_VEN_LISTING_ID = "venListingId";

    public static final String FIELD_SALE_LISTING_ID = "saleListingId";

    public static final String FIELD_TENANT_ID = "tenantId";

    public static final String FIELD_CREATE_DEPT = "createDept";

    public static final String FIELD_CREATE_TIME = "createTime";

    public static final String FIELD_CREATE_BY = "createBy";

    public static final String FIELD_UPDATE_TIME = "updateTime";

    public static final String FIELD_UPDATE_BY = "updateBy";

    public static final String FIELD_ORG_CODE = "orgCode";

    public static final String FIELD_TRADING_DATE = "tradingDate";

    public static final String FIELD_GUID = "guid";

    public static final SqlColumn<Long> column_id = table.id;

    public static final SqlColumn<String> column_tradingUnit = table.tradingUnit;

    public static final SqlColumn<String> column_tradingUnitId = table.tradingUnitId;

    public static final SqlColumn<String> column_marketId = table.marketId;

    public static final SqlColumn<LocalDate> column_targetDate = table.targetDate;

    public static final SqlColumn<Byte> column_timeCode = table.timeCode;

    public static final SqlColumn<String> column_tradingDirection = table.tradingDirection;

    public static final SqlColumn<BigDecimal> column_dealPrice = table.dealPrice;

    public static final SqlColumn<BigDecimal> column_dealEnergy = table.dealEnergy;

    public static final SqlColumn<LocalDateTime> column_bidTime = table.bidTime;

    public static final SqlColumn<LocalDateTime> column_dealTime = table.dealTime;

    public static final SqlColumn<BigDecimal> column_bidPrice = table.bidPrice;

    public static final SqlColumn<BigDecimal> column_bidEnergy = table.bidEnergy;

    public static final SqlColumn<String> column_venListingId = table.venListingId;

    public static final SqlColumn<String> column_saleListingId = table.saleListingId;

    public static final SqlColumn<String> column_tenantId = table.tenantId;

    public static final SqlColumn<Long> column_createDept = table.createDept;

    public static final SqlColumn<LocalDateTime> column_createTime = table.createTime;

    public static final SqlColumn<Long> column_createBy = table.createBy;

    public static final SqlColumn<LocalDateTime> column_updateTime = table.updateTime;

    public static final SqlColumn<Long> column_updateBy = table.updateBy;

    public static final SqlColumn<String> column_orgCode = table.orgCode;

    public static final SqlColumn<LocalDate> column_tradingDate = table.tradingDate;

    public static final SqlColumn<String> column_guid = table.guid;

    public static ExecutionInfo instance() {
        return new ExecutionInfo();
    }

    @Override
    public Table table() {
        return table;
    }

    @Override
    @SuppressWarnings("DuplicatedCode")
    public UnaryOperator<InsertDSL<ExecutionInfo>> insert() {
        return (InsertDSL<ExecutionInfo> dsl) -> {
            dsl.map(table.id).toProperty(FIELD_ID);
            dsl.map(table.tradingUnit).toProperty(FIELD_TRADING_UNIT);
            dsl.map(table.tradingUnitId).toProperty(FIELD_TRADING_UNIT_ID);
            dsl.map(table.marketId).toProperty(FIELD_MARKET_ID);
            dsl.map(table.targetDate).toProperty(FIELD_TARGET_DATE);
            dsl.map(table.timeCode).toProperty(FIELD_TIME_CODE);
            dsl.map(table.tradingDirection).toProperty(FIELD_TRADING_DIRECTION);
            dsl.map(table.dealPrice).toProperty(FIELD_DEAL_PRICE);
            dsl.map(table.dealEnergy).toProperty(FIELD_DEAL_ENERGY);
            dsl.map(table.bidTime).toProperty(FIELD_BID_TIME);
            dsl.map(table.dealTime).toProperty(FIELD_DEAL_TIME);
            dsl.map(table.bidPrice).toProperty(FIELD_BID_PRICE);
            dsl.map(table.bidEnergy).toProperty(FIELD_BID_ENERGY);
            dsl.map(table.venListingId).toProperty(FIELD_VEN_LISTING_ID);
            dsl.map(table.saleListingId).toProperty(FIELD_SALE_LISTING_ID);
            dsl.map(table.tenantId).toProperty(FIELD_TENANT_ID);
            dsl.map(table.createDept).toProperty(FIELD_CREATE_DEPT);
            dsl.map(table.createTime).toProperty(FIELD_CREATE_TIME);
            dsl.map(table.createBy).toProperty(FIELD_CREATE_BY);
            dsl.map(table.updateTime).toProperty(FIELD_UPDATE_TIME);
            dsl.map(table.updateBy).toProperty(FIELD_UPDATE_BY);
            dsl.map(table.orgCode).toProperty(FIELD_ORG_CODE);
            dsl.map(table.tradingDate).toProperty(FIELD_TRADING_DATE);
            dsl.map(table.guid).toProperty(FIELD_GUID);
            return dsl;
        };
    }

    @Override
    @SuppressWarnings("DuplicatedCode")
    public UnaryOperator<MultiRowInsertDSL<ExecutionInfo>> insertMultiple() {
        return (MultiRowInsertDSL<ExecutionInfo> dsl) -> {
            dsl.map(table.id).toProperty(FIELD_ID);
            dsl.map(table.tradingUnit).toProperty(FIELD_TRADING_UNIT);
            dsl.map(table.tradingUnitId).toProperty(FIELD_TRADING_UNIT_ID);
            dsl.map(table.marketId).toProperty(FIELD_MARKET_ID);
            dsl.map(table.targetDate).toProperty(FIELD_TARGET_DATE);
            dsl.map(table.timeCode).toProperty(FIELD_TIME_CODE);
            dsl.map(table.tradingDirection).toProperty(FIELD_TRADING_DIRECTION);
            dsl.map(table.dealPrice).toProperty(FIELD_DEAL_PRICE);
            dsl.map(table.dealEnergy).toProperty(FIELD_DEAL_ENERGY);
            dsl.map(table.bidTime).toProperty(FIELD_BID_TIME);
            dsl.map(table.dealTime).toProperty(FIELD_DEAL_TIME);
            dsl.map(table.bidPrice).toProperty(FIELD_BID_PRICE);
            dsl.map(table.bidEnergy).toProperty(FIELD_BID_ENERGY);
            dsl.map(table.venListingId).toProperty(FIELD_VEN_LISTING_ID);
            dsl.map(table.saleListingId).toProperty(FIELD_SALE_LISTING_ID);
            dsl.map(table.tenantId).toProperty(FIELD_TENANT_ID);
            dsl.map(table.createDept).toProperty(FIELD_CREATE_DEPT);
            dsl.map(table.createTime).toProperty(FIELD_CREATE_TIME);
            dsl.map(table.createBy).toProperty(FIELD_CREATE_BY);
            dsl.map(table.updateTime).toProperty(FIELD_UPDATE_TIME);
            dsl.map(table.updateBy).toProperty(FIELD_UPDATE_BY);
            dsl.map(table.orgCode).toProperty(FIELD_ORG_CODE);
            dsl.map(table.tradingDate).toProperty(FIELD_TRADING_DATE);
            dsl.map(table.guid).toProperty(FIELD_GUID);
            return dsl;
        };
    }

    @Override
    public void updateAllColumns(UpdateDSL<UpdateModel> dsl) {
        dsl.set(table.tradingUnit).equalTo(this::getTradingUnit)
           .set(table.tradingUnitId).equalTo(this::getTradingUnitId)
           .set(table.marketId).equalTo(this::getMarketId)
           .set(table.targetDate).equalTo(this::getTargetDate)
           .set(table.timeCode).equalTo(this::getTimeCode)
           .set(table.tradingDirection).equalTo(this::getTradingDirection)
           .set(table.dealPrice).equalTo(this::getDealPrice)
           .set(table.dealEnergy).equalTo(this::getDealEnergy)
           .set(table.bidTime).equalTo(this::getBidTime)
           .set(table.dealTime).equalTo(this::getDealTime)
           .set(table.bidPrice).equalTo(this::getBidPrice)
           .set(table.bidEnergy).equalTo(this::getBidEnergy)
           .set(table.venListingId).equalTo(this::getVenListingId)
           .set(table.saleListingId).equalTo(this::getSaleListingId)
           .set(table.createDept).equalTo(this::getCreateDept)
           .set(table.createTime).equalTo(this::getCreateTime)
           .set(table.createBy).equalTo(this::getCreateBy)
           .set(table.updateTime).equalTo(this::getUpdateTime)
           .set(table.updateBy).equalTo(this::getUpdateBy)
           .set(table.orgCode).equalTo(this::getOrgCode)
           .set(table.tradingDate).equalTo(this::getTradingDate)
           .set(table.guid).equalTo(this::getGuid);
        if(Objects.nonNull(getId())) {
            dsl.where(table.id, SqlBuilder.isEqualTo(this::getId));
        }
    }

    @Override
    public void updateSelectiveColumns(UpdateDSL<UpdateModel> dsl) {
        dsl.set(table.tradingUnit).equalToWhenPresent(this::getTradingUnit)
           .set(table.tradingUnitId).equalToWhenPresent(this::getTradingUnitId)
           .set(table.marketId).equalToWhenPresent(this::getMarketId)
           .set(table.targetDate).equalToWhenPresent(this::getTargetDate)
           .set(table.timeCode).equalToWhenPresent(this::getTimeCode)
           .set(table.tradingDirection).equalToWhenPresent(this::getTradingDirection)
           .set(table.dealPrice).equalToWhenPresent(this::getDealPrice)
           .set(table.dealEnergy).equalToWhenPresent(this::getDealEnergy)
           .set(table.bidTime).equalToWhenPresent(this::getBidTime)
           .set(table.dealTime).equalToWhenPresent(this::getDealTime)
           .set(table.bidPrice).equalToWhenPresent(this::getBidPrice)
           .set(table.bidEnergy).equalToWhenPresent(this::getBidEnergy)
           .set(table.venListingId).equalToWhenPresent(this::getVenListingId)
           .set(table.saleListingId).equalToWhenPresent(this::getSaleListingId)
           .set(table.tenantId).equalToWhenPresent(this::getTenantId)
           .set(table.createDept).equalToWhenPresent(this::getCreateDept)
           .set(table.createTime).equalToWhenPresent(this::getCreateTime)
           .set(table.createBy).equalToWhenPresent(this::getCreateBy)
           .set(table.updateTime).equalToWhenPresent(this::getUpdateTime)
           .set(table.updateBy).equalToWhenPresent(this::getUpdateBy)
           .set(table.orgCode).equalToWhenPresent(this::getOrgCode)
           .set(table.tradingDate).equalToWhenPresent(this::getTradingDate)
           .set(table.guid).equalToWhenPresent(this::getGuid);
        if(Objects.nonNull(getId())) {
            dsl.where(table.id, SqlBuilder.isEqualTo(this::getId));
        }
    }

    @Override
    @SuppressWarnings("all")
    public SqlColumn[] columns() {
        return new SqlColumn[]{table.id, table.tradingUnit, table.tradingUnitId, table.marketId, table.targetDate, table.timeCode, table.tradingDirection, table.dealPrice, table.dealEnergy, table.bidTime, table.dealTime, table.bidPrice, table.bidEnergy, table.venListingId, table.saleListingId, table.tenantId, table.createDept, table.createTime, table.createBy, table.updateTime, table.updateBy, table.orgCode, table.tradingDate, table.guid};
    }

    @Override
    public SqlColumn<Long> id() {
        return table.id;
    }

    @Override
    public Map<String, SqlColumn<?>> columnsMap() {
        Map<String, SqlColumn<?>> maps = new LinkedHashMap<>(24);
        maps.put(FIELD_ID, table.id);
        maps.put(FIELD_TRADING_UNIT, table.tradingUnit);
        maps.put(FIELD_TRADING_UNIT_ID, table.tradingUnitId);
        maps.put(FIELD_MARKET_ID, table.marketId);
        maps.put(FIELD_TARGET_DATE, table.targetDate);
        maps.put(FIELD_TIME_CODE, table.timeCode);
        maps.put(FIELD_TRADING_DIRECTION, table.tradingDirection);
        maps.put(FIELD_DEAL_PRICE, table.dealPrice);
        maps.put(FIELD_DEAL_ENERGY, table.dealEnergy);
        maps.put(FIELD_BID_TIME, table.bidTime);
        maps.put(FIELD_DEAL_TIME, table.dealTime);
        maps.put(FIELD_BID_PRICE, table.bidPrice);
        maps.put(FIELD_BID_ENERGY, table.bidEnergy);
        maps.put(FIELD_VEN_LISTING_ID, table.venListingId);
        maps.put(FIELD_SALE_LISTING_ID, table.saleListingId);
        maps.put(FIELD_TENANT_ID, table.tenantId);
        maps.put(FIELD_CREATE_DEPT, table.createDept);
        maps.put(FIELD_CREATE_TIME, table.createTime);
        maps.put(FIELD_CREATE_BY, table.createBy);
        maps.put(FIELD_UPDATE_TIME, table.updateTime);
        maps.put(FIELD_UPDATE_BY, table.updateBy);
        maps.put(FIELD_ORG_CODE, table.orgCode);
        maps.put(FIELD_TRADING_DATE, table.tradingDate);
        maps.put(FIELD_GUID, table.guid);
        return maps;
    }

    public static final class Table extends org.mybatis.dynamic.sql.AliasableSqlTable<Table> {
        public final SqlColumn<Long> id = column("ID", JDBCType.BIGINT);

        public final SqlColumn<String> tradingUnit = column("TRADING_UNIT", JDBCType.VARCHAR);

        public final SqlColumn<String> tradingUnitId = column("TRADING_UNIT_ID", JDBCType.VARCHAR);

        public final SqlColumn<String> marketId = column("MARKET_ID", JDBCType.VARCHAR);

        public final SqlColumn<LocalDate> targetDate = column("TARGET_DATE", JDBCType.DATE);

        public final SqlColumn<Byte> timeCode = column("TIME_CODE", JDBCType.TINYINT);

        public final SqlColumn<String> tradingDirection = column("TRADING_DIRECTION", JDBCType.VARCHAR);

        public final SqlColumn<BigDecimal> dealPrice = column("DEAL_PRICE", JDBCType.DECIMAL);

        public final SqlColumn<BigDecimal> dealEnergy = column("DEAL_ENERGY", JDBCType.DECIMAL);

        public final SqlColumn<LocalDateTime> bidTime = column("BID_TIME", JDBCType.TIMESTAMP);

        public final SqlColumn<LocalDateTime> dealTime = column("DEAL_TIME", JDBCType.TIMESTAMP);

        public final SqlColumn<BigDecimal> bidPrice = column("BID_PRICE", JDBCType.DECIMAL);

        public final SqlColumn<BigDecimal> bidEnergy = column("BID_ENERGY", JDBCType.DECIMAL);

        public final SqlColumn<String> venListingId = column("VEN_LISTING_ID", JDBCType.VARCHAR);

        public final SqlColumn<String> saleListingId = column("SALE_LISTING_ID", JDBCType.VARCHAR);

        public final SqlColumn<String> tenantId = column("TENANT_ID", JDBCType.VARCHAR);

        public final SqlColumn<Long> createDept = column("CREATE_DEPT", JDBCType.BIGINT);

        public final SqlColumn<LocalDateTime> createTime = column("CREATE_TIME", JDBCType.TIMESTAMP);

        public final SqlColumn<Long> createBy = column("CREATE_BY", JDBCType.BIGINT);

        public final SqlColumn<LocalDateTime> updateTime = column("UPDATE_TIME", JDBCType.TIMESTAMP);

        public final SqlColumn<Long> updateBy = column("UPDATE_BY", JDBCType.BIGINT);

        public final SqlColumn<String> orgCode = column("ORG_CODE", JDBCType.VARCHAR);

        public final SqlColumn<LocalDate> tradingDate = column("TRADING_DATE", JDBCType.DATE);

        public final SqlColumn<String> guid = column("GUID", JDBCType.VARCHAR);

        public Table() {
            super("ES_EXECUTION_INFO", Table::new);
        }
    }
}